package com.cssl.fmmall.controller;

import com.cssl.fmmall.entity.Users;
import com.cssl.fmmall.service.UserService;
import com.cssl.fmmall.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(value = "提供用户登录和注册功能的接口",tags = "用户管理")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name = "username",value = "用户登录账号",required = true),
            @ApiImplicitParam(dataType = "String",name = "password",value = "用户登录密码",required = true)
    })
    @GetMapping("/login")
    public Result login(@RequestParam("username") String name, @RequestParam("password")String pwd){
        return userService.checkLogin(name,pwd);
    }

    @ApiOperation("用户注册接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String",name = "username",value = "用户注册账号",required = true),
            @ApiImplicitParam(dataType = "String",name = "password",value = "用户注册密码",required = true)
    })
    @PostMapping("/reg")
    public Result reg(@RequestBody Users user){
        return userService.userReg(user.getUsername(), user.getPassword());
    }

}
